﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

namespace RegistroMascotas2
{
    public partial class contacto : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnEnviar_Click(object sender, EventArgs e)
        {
            bool exito = false;
            MailMessage msg = new MailMessage();

            msg.To.Add(new MailAddress("mariana.silvestro@outlook.com"));
            msg.From = new MailAddress("info@renacmas.com.ar");
            msg.Subject = "Registro Provincial de Mascotas: Sugerencias.";
            msg.Body = "El/La Señor/a " + nombre.Text + " con correo electronico " + correo.Text + " nos escribe: \n " + sugerencias.Text;

            SmtpClient smtp = new SmtpClient();

            smtp.Credentials = new NetworkCredential(msg.From.Address, "RENACMAS");

            smtp.Host = "mail.renacmas.com.ar";
            smtp.Port = 25;
            smtp.EnableSsl = false;

            try
            {
                smtp.Send(msg);
                exito = true;
                msg.Dispose();

                if (exito)
                {
                    resetearControles();
                    lblError.Text = "Su mensaje ha sido enviado.";
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }

        private void resetearControles()
        {
            nombre.Text = "";
            correo.Text = "";
            sugerencias.Text = "Escriba aquí sus preguntas, comentarios...";
        }
    }
}